package com.xuchaotong.zk.controller;

import com.xuchaotong.zk.utils.ZookeeperUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 311633
 * @version 1.0
 * @ClassName:
 * @Description:
 * @date 2018/1/31 14:45
 */
@RestController
public class ZookeeperController {

    private ZookeeperUtils zookeeperUtils = ZookeeperUtils.getInstance();

    @GetMapping("/add/{nodeName}")
    public String addNode(@PathVariable String nodeName) {
        String path = "/ROOTPATH/" + nodeName + "/child";
        zookeeperUtils.createNode(path, "test");
        return "SUCCESS";
    }

    @GetMapping("/del/{node}")
    public String delNode(@PathVariable String node) {
        zookeeperUtils.deleteNode("/ROOTPATH/uap3/child");
        return "SUCCESS";
    }

    @GetMapping("/modify/{val}")
    public String modifyNode(@PathVariable String val) {
        zookeeperUtils.updateNode("/ROOTPATH/pds/child", val);

        return "SUCCESS";
    }
}
